/*
package com.runfast.waimai.web.controller.business;

import com.runfast.common.web.entity.Result;
import com.runfast.waimai.utils.CompressPic;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.*;

*/
/**
 * ${DESCRIPTION}图片上传
 *
 * @author chenzheng
 * @create 2018-05-12 9:16
 **//*

@RestController("fileUploadController")
@RequestMapping("/server/fileUpload")
public class FileUploadController11111 {
    @Value("${web.upload-path}")
    private String UPLOAD_FOLDER;
    */
/***
     *
     * 图片上传
     * ***//*

    private static Set<String> imageSet = new HashSet<String>();
    static{

        imageSet.add(".png");
        imageSet.add(".jpg");
        imageSet.add(".jpeg");
        imageSet.add(".gif");
        imageSet.add(".bmp");
    }
    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestParam("upfile") MultipartFile upfile,boolean realpath){
        Map<Object,Object> map=new HashMap<Object, Object>();
        if(upfile!=null){
            Random r = new Random();
            String newFileName = System.currentTimeMillis()+"_"+r.nextInt(10000) + getExtention(upfile.getOriginalFilename());
            String realPath =UPLOAD_FOLDER;
                    //session.getServletContext().getRealPath("/upload");
            File file = new File(realPath);
            if(!file.exists()){
                file.mkdir();
            }
            String extention=getExtention(upfile.getOriginalFilename());
            if(imageSet.contains(extention)){
                File dstFile = new File(realPath,newFileName);
                try {
                    FileUtils.copyInputStreamToFile(upfile.getInputStream(), dstFile);
                    String fileName = UPLOAD_FOLDER+newFileName;
                            //Paths.get(UPLOAD_FOLDER+ newFileName).getFileName().toString();
                            //session.getServletContext().getContextPath()+"/upload/"+newFileName;
                    realPath = dstFile.getPath();
                    long fileSize = dstFile.length();
                    if(fileSize/1024>1024){//上传的图片大于1024kb才压缩
                        CompressPic.compress(realPath, dstFile, 0.8f);
                    }else if(fileSize/1024>512){//上传的图片大于512kb才压缩
                        CompressPic.compress(realPath, dstFile, 0.9f);
                    }
                    //ImageUtil.Tosmallerpic(realPath, realPath, 480, 360);

                    fileSize = dstFile.length();//压缩后的图片大小
                    map.put("fileName",upfile.getOriginalFilename());
                    map.put("filePath",fileName);
                    map.put("fileSize",fileSize);
                    if(realpath){
                        map.put("realPath", realPath);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    Result.fail(null,"保存文件时,发生错误!");
                }
            }else{
                Result.fail(null,"只能上传图片");
            }
        }else{
            Result.fail(null,"请选择要上传的文件!");
        }
    return  Result.ok(null,map);
    }

    */
/**
     * 获取文件后缀名
     * @param fileName
     * @return
     *//*

    private String getExtention(String fileName) {
        int pos = fileName.lastIndexOf(".");
        if(pos>0){
            fileName = fileName.substring(pos);
        }
        return fileName;
    }
}
*/
